<?php
require_once('entities/ShopStore.php');
class ShopStoreModel
{
	public $store;
	
	public function __construct(){
		$this->store = new ShopStore();
	}
	public function create($data) {
		global $entityManager;
		$this->store->id = $data['id'];
		$this->store->name = $data['name'];
		$this->store->address = $data['address'];
		$this->store->phone = $data['phone'];
		$this->store->status = $data['status'];
		$entityManager->persist($this->store);
		$entityManager->flush();
	}
	
	public function update($data) {
		global $entityManager;
		$this->store->id = $data['id'];
		$this->store->name = $data['name'];
		$this->store->address = $data['address'];
		$this->store->phone = $data['phone'];
		$this->store->status = $data['status'];
		$entityManager->merge($this->store);
		$entityManager->flush();
	}
	
	public function delete($id) {
		global $entityManager;
		$results = $entityManager->getRepository('ShopStore')->findBy(array('id' => $id));
		$this->store = $results[0];
		$entityManager->remove($this->store);
		$entityManager->flush();
	}
	
	public function getList() {
		global $entityManager;
		$stores = $entityManager->getRepository('ShopStore');
		$result = $stores->findAll();
		return $result;
	}
	
	public function getStore($id) {
		global $entityManager;
		$results = $entityManager->getRepository('ShopStore')->findBy(array('id' => $id));
		$result = $results[0];
		return $result;
	}
}